package com.gaeainfo.modules.alarm.process.controller;

import com.gaeainfo.framework.core.basic.dto.BaseResponseDto;
import com.gaeainfo.framework.core.utils.common.GaeaCommonUtil;
import com.gaeainfo.modules.alarm.process.service.AlarmProcessService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * Created by Caven on 2018/7/9.
 */

@Controller
@RequestMapping("rest/alarm-process")
public class AlarmProcessController {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private AlarmProcessService alarmProcessService;

    @ResponseBody
    @RequestMapping(value = "get-process")
    public BaseResponseDto getProcess(@RequestParam("processId") String processId) {
        try {
            return BaseResponseDto.successtData(alarmProcessService.getProcess(processId));
        } catch (Exception e) {
            logger.error(GaeaCommonUtil.getStackTrace(e));
            return BaseResponseDto.exception(e);
        }
    }


    @ResponseBody
    @RequestMapping(value = "update-process", method = RequestMethod.POST)
    public BaseResponseDto updateProcess(@RequestBody String processId,
                                         @RequestBody String status,
                                         @RequestBody String lngLat,
                                         @RequestBody(required = false) String policeNo,
                                         @RequestBody(required = false) String policeName) {
        try {
            return BaseResponseDto.successtData(alarmProcessService.updateProcess(processId, status, lngLat, policeNo, policeName));
        } catch (Exception e) {
            logger.error(GaeaCommonUtil.getStackTrace(e));
            return BaseResponseDto.exception(e);
        }
    }


    @ResponseBody
    @RequestMapping(value = "update-alarm-location", method = RequestMethod.POST)
    public BaseResponseDto updateAlarmLocation(@RequestBody String alarmId,
                                               @RequestBody double lng,
                                               @RequestBody double lat,
                                               @RequestBody String deptId) {
        try {
            return BaseResponseDto.successtData(alarmProcessService.updateAlarmLocation(alarmId, lng, lat, deptId));
        } catch (Exception e) {
            logger.error(GaeaCommonUtil.getStackTrace(e));
            return BaseResponseDto.exception(e);
        }
    }


}
